package com.means.polymerize.core.terminal.common.lang;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 会话存储容器
 *
 * @author xuhaifeng
 * @since 2021.10.30
 */
@Slf4j
public class SessionStorageContainer {
    /**
     * Web套接字会话发送者 存储容器
     */
    private static final ConcurrentHashMap<String, WebSocketSessionSender> SENDER_MAP = new ConcurrentHashMap<>();

    /**
     * Gets sessions.
     *
     * @return the sessions
     */
    public static WebSocketSessionSender getSessions(String token) {
        if (SENDER_MAP.containsKey(token)) {
            return SENDER_MAP.get(token);
        }
        throw new RuntimeException("会话不存在！！");
    }

    /**
     * Sets sessions.
     *
     * @param token  the token
     * @param sender the sender
     */
    public static void setSessions(String token, WebSocketSessionSender sender) {
        SENDER_MAP.put(token, sender);
    }

    public static void removeSessions(String token) {
        SENDER_MAP.remove(token);
    }
}
